{
  "properties" : { },
  "id" : "132df1e24b504aef807c77e5e67c1020",
  "script" : null,
  "groupId" : "0c2d9f4051a44b37a9a0f361f4e13b75",
  "name" : "添加项目",
  "createTime" : null,
  "updateTime" : 1731664804456,
  "lock" : "0",
  "createBy" : null,
  "updateBy" : null,
  "path" : "/add",
  "method" : "GET",
  "parameters" : [ {
    "name" : "name",
    "value" : "12331212123123",
    "description" : null,
    "required" : true,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "pass",
    "error" : "项目名称不能少于2个字",
    "expression" : "",
    "children" : null
  }, {
    "name" : "desc",
    "value" : "1312313112313",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : "项目介绍最多只能设置255个字",
    "expression" : "value.length()>255",
    "children" : null
  }, {
    "name" : "columns",
    "value" : "",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "flow",
    "value" : "open",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : "",
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "personal",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ {
    "name" : "token",
    "value" : "53407cc2-1d4f-43ae-a2c0-59aff6d5651d; JSESSIONID=D1F14ECD59B30E389DE617EF86CD4B3D",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 402,\n    \"message\": \"凭证已过期\",\n    \"data\": null,\n    \"timestamp\": 1731660898547,\n    \"executeTime\": null\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "code",
      "value" : "500",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "系统内部出现错误",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "null",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "timestamp",
      "value" : "1711608941416",
      "description" : "",
      "required" : false,
      "dataType" : "Long",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "executeTime",
      "value" : "17",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import 'cn.dev33.satoken.stp.StpUtil';
import log
import cn.hutool.core.util.IdUtil;
import http;
import '@/project/addFlow' as addFlow;
import env

var userid = StpUtil.getLoginId()

if (name.length() > 32) {
    exit 400, '项目名称最多设置32个字符'
}

var projectId

//启动事务
var val = db.transaction(() => {
    //创建项目  
    projectId = db.table('projects').insert({
        name: name,
        description: description,
        userid: userid
    })
    log.info("创建项目返回-->" + projectId)

    //插入项目用户表 
    var projectuser = db.table('project_users').insert({
        project_id: projectId,
        userid: userid,
        owner: 1
    })

    //创建工作流
    if (flow == 'open') {
        //默认的工作流配置
        var flows = [{
            "id": -10,
            "name": "待处理",
            "status": "start",
            "turns": [-10, -11, -12, -13, -14],
            "userids": "[]",
            "usertype": "add",
            // "userlimit": 0,
            "columnid": 0
        }, {
            "id": -11,
            "name": "进行中",
            "status": "progress",
            "turns": [-10, -11, -12, -13, -14],
            "userids": "[]",
            "usertype": "add",
            // "userlimit": 0,
            "columnid": 0
        }, {
            "id": -12,
            "name": "待测试",
            "status": "test",
            "turns": [-10, -11, -12, -13, -14],
            "userids": "[]",
            "usertype": "add",
            // "userlimit": 0,
            "columnid": 0
        }, {
            "id": -13,
            "name": "已完成",
            "status": "end",
            "turns": [-10, -11, -12, -13, -14],
            "userids": "[]",
            "usertype": "add",
            // "userlimit": 0,
            "columnid": 0
        }, {
            "id": -14,
            "name": "已取消",
            "status": "end",
            "turns": [-10, -11, -12, -13, -14],
            "userids": "[]",
            "usertype": "add",
            // "userlimit": 0,
            "columnid": 0
        }]
        //执行流程创建
        var projectFlowList = addFlow(flows, projectId)
    }

    
    let insertColumns = [];
    //创建项目列表
    insertColumns.push({
        'name': '默认列表',
        'sort': 0
    })

    for (index, item in insertColumns) {
        var project_columns = db.table('project_columns').insert({
            name: item.name,
            sort: item.sort,
            project_id: projectId
        })
    }

    //创建项目日志
    var project_log = db.table('project_logs').insert({
        project_id: projectId,
        column_id: 0,
        task_id: 0,
        userid: userid,
        detail: '创建项目'
    })
    //更新最后操作的项目ID到用户表
    db.table('sys_user').primary('id').update({
        id: userid,
        last_project_id: projectId
    }, true)

});
return db.table("projects").where().eq("id", projectId).selectOne()